package com.dsh.common.exeception;

import com.dsh.common.response.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    //全局异常
    @ExceptionHandler(Exception.class)
    public Result customException(Exception e){
        System.out.println("出现了Exception异常");
        e.printStackTrace();
        return new Result(false,"999",e.getMessage());
    }

    @ExceptionHandler(MyExeception.class)
    public Result myException(Exception e){
        System.out.println("出现了MyExeception异常");
        e.printStackTrace();
        return new Result(false,"333",e.getMessage());
    }

    //运行时异常
    @ExceptionHandler(RuntimeException.class)
    public Result runtimeException(Exception e){
        System.out.println("出现了RuntimeException异常");
        e.printStackTrace();
        return new Result(false,"2222",e.getMessage());
    }



}
